#include "plotpressure.h"
#include "ui_plotpressure.h"
#include "qcustomplot.h"


#define QWHITE QColor(0xff, 0xff, 0xff)
#define QBLACK QColor(0x2c, 0x2c, 0x2c)
#define QDEEPBLUE QColor(0x00, 0x00, 0xff)
#define QORANGE QColor(0xff, 0x77, 0x00)
#define QPURPLE QColor(0xd4, 0x23, 0x7a)
#define QBLUE QColor(0x12, 0x96, 0xdb)
#define QGREEN QColor(0x1a, 0xfa, 0x29)
#define QYELLOW QColor(0xf4, 0xea, 0x2a)
#define QRED QColor(0xd8, 0x1e, 0x06)

PlotPressure::PlotPressure(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PlotPressure)
{
    ui->setupUi(this);
    init();
}

PlotPressure::~PlotPressure()
{
    delete ui;
}


void PlotPressure::init()
{
    //    for (int i = 0; i < 8; ++i) {
    //        ui->mainPlot->addGraph();
    //        ui->mainPlot->graph(i)->setPen(QPen(SpectrumShowColorList[i]));
    //    }

    ui->plot_pressure->legend->setVisible(true);
    ui->plot_pressure->legend->setFont(QFont("Arial", 11));
    ui->plot_pressure->legend->setRowSpacing(-3);
    ui->plot_pressure->legend->setMargins(QMargins(200,5,10,5));
    ui->plot_pressure->legend->setFillOrder(QCPLayoutGrid::foColumnsFirst);
    ui->plot_pressure->legend->setWrap(6);
    ui->plot_pressure->plotLayout()->addElement(1 , 0, ui->plot_pressure->legend);
    ui->plot_pressure->plotLayout()->setRowStretchFactor(1, 0.001);
    ui->plot_pressure->legend->setBorderPen(Qt::NoPen);
    //ui->plotTemp->axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignTop|Qt::AlignHCenter);


    ui->plot_pressure->addGraph();
    ui->plot_pressure->graph(0)->setPen(QPen(QORANGE));
    ui->plot_pressure->graph(0)->setName(tr("Cabin Pressure"));
    ui->plot_pressure->graph()->setLineStyle((QCPGraph::LineStyle)QCPGraph::lsLine);
    ui->plot_pressure->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDiamond, 3));//设置散点形状

    ui->plot_pressure->xAxis->setRange(0,600);
    ui->plot_pressure->xAxis->ticker()->setTickCount(10);
    ui->plot_pressure->yAxis->setRange(0,300);
    ui->plot_pressure->yAxis->ticker()->setTickCount(15);

    ui->plot_pressure->xAxis->setBasePen(QPen(QBLACK));
    ui->plot_pressure->yAxis->setBasePen(QPen(QBLACK));

    ui->plot_pressure->xAxis->setTickPen(QPen(QBLACK));
    ui->plot_pressure->yAxis->setTickPen(QPen(QBLACK));

    ui->plot_pressure->xAxis->setSubTickPen(QPen(QBLACK));
    ui->plot_pressure->yAxis->setSubTickPen(QPen(QBLACK));

    ui->plot_pressure->xAxis->setTickLabelColor(QBLACK);
    ui->plot_pressure->yAxis->setTickLabelColor(QBLACK);

    ui->plot_pressure->xAxis->setLabel(tr("time/s"));
    ui->plot_pressure->xAxis->setLabelFont(QFont("Arial", 11)); // 设置字体和大小
    ui->plot_pressure->xAxis->setLabelColor(QDEEPBLUE); // 设置标签颜色
    ui->plot_pressure->xAxis->setLabelPadding(10); // 设置标签与轴之间的间距

    ui->plot_pressure->yAxis->setLabel(tr("CabinPressure/KPa"));
    ui->plot_pressure->yAxis->setLabelFont(QFont("Arial", 11)); // 设置字体和大小
    ui->plot_pressure->yAxis->setLabelColor(QDEEPBLUE); // 设置标签颜色
    ui->plot_pressure->yAxis->setLabelPadding(10); // 设置标签与轴之间的间距

    ui->plot_pressure->setBackground(QBrush(QWHITE));//设置背景色
    ui->plot_pressure->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
    ui->plot_pressure->replot();
}

void PlotPressure::drawPlot(const double & time , const double& data)
{
    ui->plot_pressure->graph()->addData(time,data);
    ui->plot_pressure->rescaleAxes(true);
    ui->plot_pressure->replot();
}

void PlotPressure::clearPlot()
{
    ui->plot_pressure->graph()->data()->clear();
    ui->plot_pressure->rescaleAxes(true);
    ui->plot_pressure->replot();
}


